import java.util.concurrent.CountDownLatch;

public class ZHUZHUXIA
{
    private final CountDownLatch latch = new CountDownLatch(1);

    //魔童哪吒
    private Integer babyTickets = 20;

    //蜘蛛侠
    private Integer spiderTickets = 100;

    public synchronized void showBabyTickets() throws InterruptedException
    {
        System.out.println("魔童哪吒的剩余票数为：" + babyTickets);
        //购买
        latch.await();
    }

    public synchronized void showSpiderTickets() throws InterruptedException
    {
        System.out.println("蜘蛛侠的剩余票数为：" + spiderTickets);
        //购买
    }

    public static void main(String[] args)
    {
        ZHUZHUXIA movie = new ZHUZHUXIA();
        new Thread(() -> {
            try
            {
                movie.showBabyTickets();
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }, "用户A").start();
        new Thread(() -> {
            try
            {
                movie.showSpiderTickets();
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }, "用户B").start();
    }
}
